package com.ajax.browser;

import java.net.URL;

public class ClientletRequestImpl implements ClientletRequest {

	private final String method;
	private final URL url;
	private final ParameterInfo paramInfo;
	private final Header[] extraHeaders;
	private final boolean forNewWindow;
	private final String referrer;
	private final String altPostData;
	
	public ClientletRequestImpl(boolean forNewWindow, URL url, String method, ParameterInfo paramInfo, Header[] extraHeaders, String referrer, String altPostData) {
		this.method = method;
		this.url = url;
		this.paramInfo = paramInfo;
		this.extraHeaders = extraHeaders;
		this.forNewWindow = forNewWindow;
		this.referrer = referrer;
		this.altPostData = altPostData;
	}

	public ClientletRequestImpl(boolean forNewWindow, URL url, String method, ParameterInfo paramInfo) {
		this(forNewWindow, url, method, paramInfo, null, null, null);
	}

	public ClientletRequestImpl(URL url) {
		this(false, url, "GET", null, null, null, null);
	}

	public ClientletRequestImpl(boolean forNewWindow, URL url) {
		this(forNewWindow, url, "GET", null, null, null, null);
	}

	public ClientletRequestImpl(URL url, String method, String altPostData) {
		this(false, url, method, null, null, null, altPostData);
	}

	public Header[] getExtraHeaders() {
		return this.extraHeaders;
	}

	public String getMethod() {
		return this.method;
	}

	public ParameterInfo getParameterInfo() {
		return this.paramInfo;
	}

	public URL getRequestURL() {
		return this.url;
	}

	public UserAgent getUserAgent() {
		return UserAgentImpl.getInstance();
	}

	public boolean isGetRequest() {
		return "GET".equalsIgnoreCase(method);
	}

	public boolean isNewWindowRequest() {
		return this.forNewWindow;
	}

	public boolean isPostRequest() {
		return "POST".equalsIgnoreCase(this.method);
	}

	public String getReferrer() {
		return this.referrer;
	}

	public String getAltPostData() {
		return this.altPostData;
	}
}
